/*******************************************************************************

  Paying Outsourced Labor: Direct Evidence from Linked Temp Agency-Worker-Client Data

  By Andres Drenik, Simon Jäger, Pascuel Plotkin and Benjamin Schoefer
  January 7th, 2021

	DESCRIPTION: Creates Figures A.3 Of Appendix

*******************************************************************************/




/********************************************************************************
***** Preliminaries
********************************************************************************/
set more off
cap log close
local curr_date = c(current_date)
log using "${logs}/FigA3`curr_date'", replace


/****************************************************************************************
* Load Dataset
****************************************************************************************/

use "${intermediate_data_emp}/dataset_AKM_estimation.dta", clear

/****************************************************************************************
* Run Figures
****************************************************************************************/

*Appendix Figure A.3 (Sorting in the Temp Agency Market: Estimated Firm Effects for Temp Agencies and Regular Firm)
	*Binscatter Y-Axis: Temp Agency Firm FE; X-Axis: Firm FE (as Regular Firms)
	binscatter temp_fe4 firm_fe4 [fw=obs] if temp_fe4 != 0 & temp_fe4 != . & firm_fe4 != 0 & firm_fe4 != . & temp_worker > 0 & temp_worker !=., ytitle("Firm FE for Temporary Work Agencies", size(medium)) xtitle("Firm FE for Regular Workers", size(medium))  xsize(16) ysize(9)
	graph export "${Results}/Figure_A3_reg_appendix.pdf", replace

	qui reg temp_fe4 firm_fe4 [fw=obs] if temp_fe4 != 0 & temp_fe4 != . & firm_fe4 != 0 & firm_fe4 != . & temp_worker > 0 & temp_worker !=.
	local beta_firm_fe4_a3 = _b[firm_fe4]
	local se_firm_fe4_a3 = _se[firm_fe4]

    *Keep register of slopes and SE
	matrix beta= [(`beta_firm_fe4_a3')]'
	matrix s_e= [(`se_firm_fe4_a3')]'

	cd "${Results}"

	putexcel set "Slope_and_SE_Figure_A3_appendix", sheet("Slope_SE") modify
	putexcel A1=("Regression") B1=("Beta") C1=("SE")
	putexcel A2=("firm_fe4_a3")
	putexcel B2=matrix (beta) C2=matrix(s_e)

log close
